package com.manage.server.controller.admin;

import com.manage.dto.UserPermissionDTO;
import com.manage.dto.add.UserPermissionAddDTO;
import com.manage.dto.update.UserPermissionUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.UserPermissionService;
import com.manage.vo.UserPermissionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("userPermission")
public class UserPermissionController {

    @Autowired
    private UserPermissionService userPermissionService;

    @PostMapping
    public Result add(@RequestBody UserPermissionAddDTO userPermissionAddDTO) {
        userPermissionService.save(userPermissionAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        userPermissionService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody UserPermissionUpdateDTO userPermissionUpdateDTO) {
        userPermissionService.updateById(userPermissionUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param userPermissionDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<UserPermissionVO> findUserPermission(@RequestBody UserPermissionDTO userPermissionDTO) {
        return userPermissionService.findUserPermissionByPage(userPermissionDTO);
    }
}